<template>
  <view class="fixedTop" v-if="isShare">
    <view class="top-nav-box">
      <view class="back-icon-box" v-if="isShare" @click="backClick">
        <image class="back-icon" src="@/static/img/black-back.png" mode="aspectFit"></image>
      </view>
      <view class="back-icon-box" v-else>
        <view class="back-icon"></view>
      </view>
      <view class="nav-center" style="font-size: 34rpx">{{title}}</view>
      <view class="nav-right">
        <view class="top-button" v-if="choose">
          <view class='conform' @click="chooseAddress()">完成</view>
        </view>
        <view class="image-wrapper" v-if="isShare&&!askus&&!choose" @click="share"><image src="@/static/img/icon/share-wx-icon.png" mode="aspectFit"></image></view>
        <view class="image-wrapper" v-if="askus&&!choose" @click="goShare"><image src="@/static/img/share.png" mode="aspectFit"></image></view>
        <view class="image-wrapper2" @click="$refs.telephoneServiceTel.$refs.popupTel.open()"><image src="@/static/img/icon/index-kf.png" mode="aspectFit"></image></view>
      </view>
    </view>
    <!-- 客服组件 -->
    <order-telephone name="如有技术问题请联系" phoneNumber="18820268653" ref="telephoneServiceTel"></order-telephone>
  </view>
</template>

<script>
export default {
  props:{
    shareTitle:'',
    shareContent:'',
    sale:'',//销售数量
    askus: {
      type:Boolean,
      default:false
    },
    choose:{
      type:Boolean,
      default:false
    },
    title:''
  },
  data() {
    return {
      isShare:this.$route.query.type=='share' ? false : true
    };
  },
  created() {
    this.gettopColor()
  },
  methods: {
    //选择地址
    chooseAddress(){
        this.$emit('chooseAddress')
    },
    //判断顶部颜色
    gettopColor(){
      const nav = navigator.userAgent;
      if (nav.indexOf('Android') > -1 || nav.indexOf('Adr') > -1) {
        phone.setStatusBarColor("#ffffff")
      } else if (!!nav.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        this.$bridge.callhandler('backgroundColorChange', {topColor:'#ffffff',bottomColor:"#ffffff"}, res => {});
      }
    },
    //分享
    share(){
      let shareInfo = {
        title: this.shareTitle,
        content: this.shareContent,
        imageUrl: `${this.$API_URL}/source/go.png`,
        path:  `http://falizg.com/`
      // path: `${this.$VIEW_URL}/#/pages/client/order/order-court-own?area_id=${this.$route.query.area_id}&bearFees=${this.$route.query.bearFees}&product_id=${this.$route.query.product_id}&product_image=${this.$route.query.product_image}&product_name=${this.$route.query.product_name}&type=share&sale=${this.sale}`
      };
      const nav = navigator.userAgent;
      if (nav.indexOf('Android') > -1 || nav.indexOf('Adr') > -1) {
        phone.share(JSON.stringify(shareInfo));
      } else if (!!nav.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        this.$bridge.callhandler('share', shareInfo, data => {
          // 处理返回数据
          console.log(data, '我走了这里');
        });
      }
    },
    goShare(){
      this.$emit('goShare')
    },
    backClick(){
      uni.navigateBack({
        delta: 2
      });
    }
  }
};
</script>

<style lang="scss">
.top-button {
  box-sizing: border-box;
  padding: 24rpx;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  .cancel {
    // color: white;
    background-color: #fafafa;
    padding: 8rpx 14rpx;
    border-radius: 8rpx;
  }
  .conform {
    background: #FFC900;
    padding: 0rpx 12rpx;
    border-radius: 6rpx;
    color:#Fff;
    height: 50rpx;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}
.receiveCouponBox {
  padding: 30rpx;
  .ipt-border {
    margin-bottom: 20rpx;
    padding: 18rpx;
  }
}
.top-nav-box {
  background: #fff;
  color: #000;
  text-align: center;
  position: relative;
  height: 88rpx;
  line-height: 88rpx;
  font-size: 30rpx;
  display: flex;
  padding: 0rpx 16rpx;
  box-shadow: 0px 15px 7px -21px #000;
  .back-icon-box{
    flex: 1;
    height: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    .back-icon{
      width: 32rpx;
      height: 30rpx;
    }
  }
  .nav-center {
    flex: 1;
  }
  .nav-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    .image-wrapper {
      margin-top: 15rpx;
      margin-right: 30rpx;
      width: 50rpx;
      height: 60rpx;
      image {
        width: 100%;
        height: 100%;
      }
    }
    .image-wrapper2 {
      margin-top: 15rpx;
      width: 50rpx;
      height: 60rpx;
      image {
        width: 100%;
        height: 100%;
      }
    }
  }
}
.item-popup {
  margin: 0 auto;
  .item-txt {
    height: 28rpx;
    font-size: 20rpx;
    margin: 0 auto;
    color: #000;
  }
  .img1 {
    width: 330rpx;
    height: 86rpx;
    margin: 0 auto;
    image {
      width: 100%;
      height: 100%;
    }
  }
  .img2 {
    width: 376rpx;
    height: 260rpx;
    margin: 20rpx auto 0;
    image {
      width: 100%;
      height: 100%;
    }
  }
  .img3 {
    width: 200rpx;
    height: 60rpx;
    margin: 15rpx auto;
    image {
      width: 100%;
      height: 100%;
    }
  }
  .img4 {
    width: 40rpx;
    height: 40rpx;
    margin: 20rpx auto;
    image {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
